/*
 *  JDialogNovoPacote.java
 *  Copyright (C) 2008  Tiago Silva Loureiro
 *  This File is part of Bier Manager.
 *  Bier Manager is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Created on 24 de Setembro de 2008, 18:36
 * 
 * //TODO : Inserir um botao de interrogacao afirmando tamanho e extensão do campo.
 * 
 */

package biermanager.editorDeTimes.interfaceGrafica;


import biermanager.editorDeTimes.uteis.LimitaEdits;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JOptionPane;

/**
 *
 * @author  tiagoloureiro
 */
public class JDialogNovoPacote extends javax.swing.JDialog {

    /** Creates new form JDialogNovoPacote
     * @param parent
     * @param modal 
     */
    public JDialogNovoPacote(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();  
        setLocation( (int)( ( screenSize.getWidth() - this.getWidth() ) / 2 ), (int)( (screenSize.getHeight() - this.getHeight() - 40) / 2 ) );
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        jlCriarNovoPacote = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jlNomeDoPacote = new javax.swing.JLabel();
        jtfNomeDoPacote = new javax.swing.JTextField();
        jbtCriar = new javax.swing.JButton();
        jbtCancelar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Criar Pacote");
        setModal(true);
        setResizable(false);

        jlCriarNovoPacote.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jlCriarNovoPacote.setText("Criar novo Pacote de Times");

        jlNomeDoPacote.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jlNomeDoPacote.setText("Nome do novo Pacote de Times:");

        jtfNomeDoPacote.setDocument(new LimitaEdits(13));
        jtfNomeDoPacote.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jtfNomeDoPacote.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfNomeDoPacoteActionPerformed(evt);
            }
        });

        jbtCriar.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jbtCriar.setText("Criar");
        jbtCriar.setToolTipText("Clique para criar um novo Pacote de Times");
        jbtCriar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtCriarActionPerformed(evt);
            }
        });

        jbtCancelar.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jbtCancelar.setText("Cancelar");
        jbtCancelar.setToolTipText("Clique para cancelar a criação de um novo pacote de times");
        jbtCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jlNomeDoPacote, javax.swing.GroupLayout.DEFAULT_SIZE, 344, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jbtCancelar, javax.swing.GroupLayout.DEFAULT_SIZE, 154, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(jbtCriar, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jtfNomeDoPacote, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 344, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jlNomeDoPacote)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jtfNomeDoPacote, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(20, 20, 20)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jbtCriar, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbtCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jlCriarNovoPacote, javax.swing.GroupLayout.Alignment.LEADING))
                .addContainerGap(14, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jlCriarNovoPacote, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(112, 112, 112))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 192, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jtfNomeDoPacoteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfNomeDoPacoteActionPerformed

}//GEN-LAST:event_jtfNomeDoPacoteActionPerformed

private void jbtCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtCancelarActionPerformed
    this.dispose();
}//GEN-LAST:event_jbtCancelarActionPerformed

private void jbtCriarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtCriarActionPerformed
    if( verificaCampos() )
    this.dispose();
}//GEN-LAST:event_jbtCriarActionPerformed

    /**
     *  @return True se todos os campos estão preenchidos corretamente.
    */
    public boolean verificaCampos(){
        if( !(jtfNomeDoPacote.getText().isEmpty()) && jtfNomeDoPacote.getText().length() < 13 && jtfNomeDoPacote.getText().length() > 4 )
            if( jtfNomeDoPacote.getText().endsWith(".tim" ) ){
                nomeDoArquivo = jtfNomeDoPacote.getText();
                return(true);
            }
            else{
                JOptionPane.showMessageDialog(null, "Arquivo dever terminar com a extensao ' .tim '   !");
            return(false);
            }
    else{
            JOptionPane.showMessageDialog(null, "O nome do arquivo não pode ser vazio, deve conter a extensao '.tim' e conter mais de 8 caracteres!");
            return(false);
    }
}

public String getNomeDoArquivo(){
        return( nomeDoArquivo );
}

    String nomeDoArquivo;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JButton jbtCancelar;
    private javax.swing.JButton jbtCriar;
    private javax.swing.JLabel jlCriarNovoPacote;
    private javax.swing.JLabel jlNomeDoPacote;
    private javax.swing.JTextField jtfNomeDoPacote;
    // End of variables declaration//GEN-END:variables

}
